﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dropit.BlogPageProvider.Blog;

namespace Dropit.BlogPageProvider.WordPress
{
	public class Blog : IBlog
	{
		public static List<Blog> List(JoeBlogs.WordPressWrapper wrapper)
		{
			try
			{
				return wrapper.GetUserBlogs().Select<JoeBlogs.Structs.UserBlog, Blog>(blog => new Blog()
				{
					WordPressId = new WordPressId()
					{
						BlogId = blog.blogid
					},
					Name = blog.blogName,
					Summery = string.Empty,
					Created = DateTime.Now
				}).ToList<Blog>();
			}
			catch (Exception ex)
			{
			}
			return new List<Blog>(0);
		}

		public static Blog Load(JoeBlogs.WordPressWrapper wrapper, WordPressId id)
		{
			return List(wrapper).First(blog => blog.WordPressId.BlogId == id.BlogId);
		}

		public WordPressId WordPressId
		{
			get;
			set;
		}

		#region IBlog Members

		public string Id
		{
			get { return WordPressId.ToString(); }
		}

		public string Name
		{
			get;
			set;
		}

		public string Summery
		{
			get;
			set;
		}

		public DateTime Created
		{
			get;
			set;
		}

		#endregion
	}
}
